<template>
  <div class="legend">
    <div
      class="legend-list"
      v-for="(item, index) in legend"
      :key="index"
      :style="`background-color: ${itemBg};width: ${itemWidth}; height: ${itemHeight}`"
    >
      <div class="legend-title">
        <span
          ref="shape"
          class="color-dot"
          :style="`background-color: ${item.color};width: ${wd}; height: ${he}; `"
        ></span>
        <span class="title">{{ item.name }}</span>
      </div>
      <div class="data">
        <span class="num">{{ item.value }}</span>
        <span class="unit">{{ unit }}</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DafosiControlWebLegend',

  props: {
    shape: {
      type: String,
      default: 'dot'
    },
    wd: {
      type: String,
      default: '0.6rem'
    },
    he: {
      type: String,
      default: '0.6rem'
    },
    unit: {
      type: String,
      default: '吨'
    },
    itemWidth: {
      type: String,
      default: '6.25rem'
    },
    itemHeight: {
      type: String,
      default: '1.5rem'
    },
    itemBg: {
      type: String,
      default: 'rgba(255,255,255,.1)'
    },
    legend: {
      type: Array,
      default: () => []
    }
  },

  data() {
    return {
    };
  },

  mounted() {
    if (this.shape === 'dot') {
      this.$refs.shape.forEach((item) => {
        item.style.borderRadius = '100%';
      });
    }
  },

  methods: {}
};
</script>

<style lang="scss" scoped>
.legend {
  &-list {
    display: flex;
    line-height: 1;
    align-items: center;
    justify-content: space-between;
    padding: 0.3125rem;
    .legend-title {
      .color-dot {
        display: inline-block;
        vertical-align: middle;
      }
      .title {
        font-size: 0.75rem;
        height: 0.75rem;
        line-height: 1;
        margin-left: 0.25rem;
      }
    }
    .data {
      .num {
        font-size: 0.75rem;
      }
      .unit {
        font-size: 0.75rem;
        color: #a2a7ba;
        margin-left: 0.25rem;
      }
    }
  }
  &-list:not(:first-child) {
    margin-top: 0.625rem;
  }
}
</style>
